<?php

/**
 * InboundPlan.
 *
 * PHP version 8.3
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * The Selling Partner API for FBA inbound operations.
 *
 * The Selling Partner API for Fulfillment By Amazon (FBA) Inbound. The FBA Inbound API enables building inbound workflows to create, manage, and send shipments into Amazon's fulfillment network. The API has interoperability with the Send-to-Amazon user interface.
 *
 * The version of the OpenAPI document: 2024-03-20
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.9.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace SpApi\Model\fulfillment\inbound\v2024_03_20;

use SpApi\Model\ModelInterface;
use SpApi\ObjectSerializer;

/**
 * InboundPlan Class Doc Comment.
 *
 * @category Class
 *
 * @description Inbound plan containing details of the inbound workflow.
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @implements \ArrayAccess<string, mixed>
 */
class InboundPlan implements ModelInterface, \ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

    /**
     * The original name of the model.
     */
    protected static string $openAPIModelName = 'InboundPlan';

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static array $openAPITypes = [
        'created_at' => '\DateTime',
        'inbound_plan_id' => 'string',
        'last_updated_at' => '\DateTime',
        'marketplace_ids' => 'string[]',
        'name' => 'string',
        'packing_options' => '\SpApi\Model\fulfillment\inbound\v2024_03_20\PackingOptionSummary[]',
        'placement_options' => '\SpApi\Model\fulfillment\inbound\v2024_03_20\PlacementOptionSummary[]',
        'shipments' => '\SpApi\Model\fulfillment\inbound\v2024_03_20\ShipmentSummary[]',
        'source_address' => '\SpApi\Model\fulfillment\inbound\v2024_03_20\Address',
        'status' => 'string'];

    /**
     * Array of property to format mappings. Used for (de)serialization.
     *
     * @var string[]
     *
     * @phpstan-var array<string, string|null>
     *
     * @psalm-var array<string, string|null>
     */
    protected static array $openAPIFormats = [
        'created_at' => 'date-time',
        'inbound_plan_id' => null,
        'last_updated_at' => 'date-time',
        'marketplace_ids' => null,
        'name' => null,
        'packing_options' => null,
        'placement_options' => null,
        'shipments' => null,
        'source_address' => null,
        'status' => null];

    /**
     * Array of nullable properties. Used for (de)serialization.
     *
     * @var bool[]
     */
    protected static array $openAPINullables = [
        'created_at' => false,
        'inbound_plan_id' => false,
        'last_updated_at' => false,
        'marketplace_ids' => false,
        'name' => false,
        'packing_options' => true,
        'placement_options' => true,
        'shipments' => true,
        'source_address' => false,
        'status' => false,
    ];

    /**
     * If a nullable field gets set to null, insert it here.
     *
     * @var bool[]
     */
    protected array $openAPINullablesSetToNull = [];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     *
     * @var string[]
     */
    protected static array $attributeMap = [
        'created_at' => 'createdAt',
        'inbound_plan_id' => 'inboundPlanId',
        'last_updated_at' => 'lastUpdatedAt',
        'marketplace_ids' => 'marketplaceIds',
        'name' => 'name',
        'packing_options' => 'packingOptions',
        'placement_options' => 'placementOptions',
        'shipments' => 'shipments',
        'source_address' => 'sourceAddress',
        'status' => 'status',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static array $setters = [
        'created_at' => 'setCreatedAt',
        'inbound_plan_id' => 'setInboundPlanId',
        'last_updated_at' => 'setLastUpdatedAt',
        'marketplace_ids' => 'setMarketplaceIds',
        'name' => 'setName',
        'packing_options' => 'setPackingOptions',
        'placement_options' => 'setPlacementOptions',
        'shipments' => 'setShipments',
        'source_address' => 'setSourceAddress',
        'status' => 'setStatus',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static array $getters = [
        'created_at' => 'getCreatedAt',
        'inbound_plan_id' => 'getInboundPlanId',
        'last_updated_at' => 'getLastUpdatedAt',
        'marketplace_ids' => 'getMarketplaceIds',
        'name' => 'getName',
        'packing_options' => 'getPackingOptions',
        'placement_options' => 'getPlacementOptions',
        'shipments' => 'getShipments',
        'source_address' => 'getSourceAddress',
        'status' => 'getStatus',
    ];

    /**
     * Associative array for storing property values.
     */
    protected array $container = [];

    /**
     * Constructor.
     *
     * @param null|array $data Associated array of property values
     *                         initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('created_at', $data ?? [], null);
        $this->setIfExists('inbound_plan_id', $data ?? [], null);
        $this->setIfExists('last_updated_at', $data ?? [], null);
        $this->setIfExists('marketplace_ids', $data ?? [], null);
        $this->setIfExists('name', $data ?? [], null);
        $this->setIfExists('packing_options', $data ?? [], null);
        $this->setIfExists('placement_options', $data ?? [], null);
        $this->setIfExists('shipments', $data ?? [], null);
        $this->setIfExists('source_address', $data ?? [], null);
        $this->setIfExists('status', $data ?? [], null);
    }

    /**
     * Gets the string presentation of the object.
     *
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT
        );
    }

    /**
     * Array of property to type mappings. Used for (de)serialization.
     */
    public static function openAPITypes(): array
    {
        return self::$openAPITypes;
    }

    /**
     * Array of property to format mappings. Used for (de)serialization.
     */
    public static function openAPIFormats(): array
    {
        return self::$openAPIFormats;
    }

    /**
     * Checks if a property is nullable.
     */
    public static function isNullable(string $property): bool
    {
        return self::openAPINullables()[$property] ?? false;
    }

    /**
     * Checks if a nullable property is set to null.
     */
    public function isNullableSetToNull(string $property): bool
    {
        return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     */
    public static function attributeMap(): array
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     */
    public static function setters(): array
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests).
     */
    public static function getters(): array
    {
        return self::$getters;
    }

    /**
     * The original name of the model.
     */
    public function getModelName(): string
    {
        return self::$openAPIModelName;
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties(): array
    {
        $invalidProperties = [];

        if (null === $this->container['created_at']) {
            $invalidProperties[] = "'created_at' can't be null";
        }
        if (null === $this->container['inbound_plan_id']) {
            $invalidProperties[] = "'inbound_plan_id' can't be null";
        }
        if (mb_strlen($this->container['inbound_plan_id']) > 38) {
            $invalidProperties[] = "invalid value for 'inbound_plan_id', the character length must be smaller than or equal to 38.";
        }

        if (mb_strlen($this->container['inbound_plan_id']) < 38) {
            $invalidProperties[] = "invalid value for 'inbound_plan_id', the character length must be bigger than or equal to 38.";
        }

        if (!preg_match('/^[a-zA-Z0-9-]*$/', $this->container['inbound_plan_id'])) {
            $invalidProperties[] = "invalid value for 'inbound_plan_id', must be conform to the pattern /^[a-zA-Z0-9-]*$/.";
        }

        if (null === $this->container['last_updated_at']) {
            $invalidProperties[] = "'last_updated_at' can't be null";
        }
        if (null === $this->container['marketplace_ids']) {
            $invalidProperties[] = "'marketplace_ids' can't be null";
        }
        if (null === $this->container['name']) {
            $invalidProperties[] = "'name' can't be null";
        }
        if (null === $this->container['source_address']) {
            $invalidProperties[] = "'source_address' can't be null";
        }
        if (null === $this->container['status']) {
            $invalidProperties[] = "'status' can't be null";
        }
        if (mb_strlen($this->container['status']) > 1024) {
            $invalidProperties[] = "invalid value for 'status', the character length must be smaller than or equal to 1024.";
        }

        if (mb_strlen($this->container['status']) < 1) {
            $invalidProperties[] = "invalid value for 'status', the character length must be bigger than or equal to 1.";
        }

        return $invalidProperties;
    }

    /**
     * Validate all the properties in the model
     * return true if all passed.
     *
     * @return bool True if all properties are valid
     */
    public function valid(): bool
    {
        return 0 === count($this->listInvalidProperties());
    }

    /**
     * Gets created_at.
     */
    public function getCreatedAt(): \DateTime
    {
        return $this->container['created_at'];
    }

    /**
     * Sets created_at.
     *
     * @param \DateTime $created_at The time at which the inbound plan was created. In [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) datetime with pattern `yyyy-MM-ddTHH:mm:ssZ`.
     */
    public function setCreatedAt(\DateTime $created_at): self
    {
        if (is_null($created_at)) {
            throw new \InvalidArgumentException('non-nullable created_at cannot be null');
        }
        $this->container['created_at'] = $created_at;

        return $this;
    }

    /**
     * Gets inbound_plan_id.
     */
    public function getInboundPlanId(): string
    {
        return $this->container['inbound_plan_id'];
    }

    /**
     * Sets inbound_plan_id.
     *
     * @param string $inbound_plan_id identifier of an inbound plan
     */
    public function setInboundPlanId(string $inbound_plan_id): self
    {
        if (is_null($inbound_plan_id)) {
            throw new \InvalidArgumentException('non-nullable inbound_plan_id cannot be null');
        }
        if (mb_strlen($inbound_plan_id) > 38) {
            throw new \InvalidArgumentException('invalid length for $inbound_plan_id when calling InboundPlan., must be smaller than or equal to 38.');
        }
        if (mb_strlen($inbound_plan_id) < 38) {
            throw new \InvalidArgumentException('invalid length for $inbound_plan_id when calling InboundPlan., must be bigger than or equal to 38.');
        }
        if (!preg_match('/^[a-zA-Z0-9-]*$/', ObjectSerializer::toString($inbound_plan_id))) {
            throw new \InvalidArgumentException('invalid value for $inbound_plan_id when calling InboundPlan., must conform to the pattern /^[a-zA-Z0-9-]*$/.');
        }

        $this->container['inbound_plan_id'] = $inbound_plan_id;

        return $this;
    }

    /**
     * Gets last_updated_at.
     */
    public function getLastUpdatedAt(): \DateTime
    {
        return $this->container['last_updated_at'];
    }

    /**
     * Sets last_updated_at.
     *
     * @param \DateTime $last_updated_at The time at which the inbound plan was last updated. In [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) datetime format with pattern `yyyy-MM-ddTHH:mm:ssZ`.
     */
    public function setLastUpdatedAt(\DateTime $last_updated_at): self
    {
        if (is_null($last_updated_at)) {
            throw new \InvalidArgumentException('non-nullable last_updated_at cannot be null');
        }
        $this->container['last_updated_at'] = $last_updated_at;

        return $this;
    }

    /**
     * Gets marketplace_ids.
     */
    public function getMarketplaceIds(): array
    {
        return $this->container['marketplace_ids'];
    }

    /**
     * Sets marketplace_ids.
     *
     * @param array $marketplace_ids a list of marketplace IDs
     */
    public function setMarketplaceIds(array $marketplace_ids): self
    {
        if (is_null($marketplace_ids)) {
            throw new \InvalidArgumentException('non-nullable marketplace_ids cannot be null');
        }
        $this->container['marketplace_ids'] = $marketplace_ids;

        return $this;
    }

    /**
     * Gets name.
     */
    public function getName(): string
    {
        return $this->container['name'];
    }

    /**
     * Sets name.
     *
     * @param string $name human-readable name of the inbound plan
     */
    public function setName(string $name): self
    {
        if (is_null($name)) {
            throw new \InvalidArgumentException('non-nullable name cannot be null');
        }
        $this->container['name'] = $name;

        return $this;
    }

    /**
     * Gets packing_options.
     */
    public function getPackingOptions(): ?array
    {
        return $this->container['packing_options'];
    }

    /**
     * Sets packing_options.
     *
     * @param null|array $packing_options Packing options for the inbound plan. This property will be populated when it has been generated via the corresponding operation. If there is a chosen placement option, only packing options for that placement option will be returned. If there are confirmed shipments, only packing options for those shipments will be returned. Query the packing option for more details.
     */
    public function setPackingOptions(?array $packing_options): self
    {
        if (is_null($packing_options)) {
            array_push($this->openAPINullablesSetToNull, 'packing_options');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('packing_options', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['packing_options'] = $packing_options;

        return $this;
    }

    /**
     * Gets placement_options.
     */
    public function getPlacementOptions(): ?array
    {
        return $this->container['placement_options'];
    }

    /**
     * Sets placement_options.
     *
     * @param null|array $placement_options Placement options for the inbound plan. This property will be populated when it has been generated via the corresponding operation. If there is a chosen placement option, that will be the only returned option. Query the placement option for more details.
     */
    public function setPlacementOptions(?array $placement_options): self
    {
        if (is_null($placement_options)) {
            array_push($this->openAPINullablesSetToNull, 'placement_options');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('placement_options', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['placement_options'] = $placement_options;

        return $this;
    }

    /**
     * Gets shipments.
     */
    public function getShipments(): ?array
    {
        return $this->container['shipments'];
    }

    /**
     * Sets shipments.
     *
     * @param null|array $shipments A list of shipment IDs for the inbound plan. This property is populated when it has been generated with the `confirmPlacementOptions` operation. Only shipments from the chosen placement option are returned. Query the shipment for more details.
     */
    public function setShipments(?array $shipments): self
    {
        if (is_null($shipments)) {
            array_push($this->openAPINullablesSetToNull, 'shipments');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('shipments', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['shipments'] = $shipments;

        return $this;
    }

    /**
     * Gets source_address.
     */
    public function getSourceAddress(): Address
    {
        return $this->container['source_address'];
    }

    /**
     * Sets source_address.
     *
     * @param Address $source_address source_address
     */
    public function setSourceAddress(Address $source_address): self
    {
        if (is_null($source_address)) {
            throw new \InvalidArgumentException('non-nullable source_address cannot be null');
        }
        $this->container['source_address'] = $source_address;

        return $this;
    }

    /**
     * Gets status.
     */
    public function getStatus(): string
    {
        return $this->container['status'];
    }

    /**
     * Sets status.
     *
     * @param string $status Current status of the inbound plan. Possible values: `ACTIVE`, `VOIDED`, `SHIPPED`, `ERRORED`.
     */
    public function setStatus(string $status): self
    {
        if (is_null($status)) {
            throw new \InvalidArgumentException('non-nullable status cannot be null');
        }
        if (mb_strlen($status) > 1024) {
            throw new \InvalidArgumentException('invalid length for $status when calling InboundPlan., must be smaller than or equal to 1024.');
        }
        if (mb_strlen($status) < 1) {
            throw new \InvalidArgumentException('invalid length for $status when calling InboundPlan., must be bigger than or equal to 1.');
        }

        $this->container['status'] = $status;

        return $this;
    }

    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param int $offset Offset
     */
    public function offsetExists($offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param int $offset Offset
     *
     * @return null|mixed
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($offset): mixed
    {
        return $this->container[$offset] ?? null;
    }

    /**
     * Sets value based on offset.
     *
     * @param null|int $offset Offset
     * @param mixed    $value  Value to be set
     */
    public function offsetSet($offset, mixed $value): void
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     *
     * @param int $offset Offset
     */
    public function offsetUnset($offset): void
    {
        unset($this->container[$offset]);
    }

    /**
     * Serializes the object to a value that can be serialized natively by json_encode().
     *
     * @see https://www.php.net/manual/en/jsonserializable.jsonserialize.php
     *
     * @return mixed returns data which can be serialized by json_encode(), which is a value
     *               of any type other than a resource
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize(): mixed
    {
        return ObjectSerializer::sanitizeForSerialization($this);
    }

    /**
     * Gets a header-safe presentation of the object.
     */
    public function toHeaderValue(): string
    {
        return json_encode(ObjectSerializer::sanitizeForSerialization($this));
    }

    /**
     * Array of nullable properties.
     */
    protected static function openAPINullables(): array
    {
        return self::$openAPINullables;
    }

    /**
     * Array of nullable field names deliberately set to null.
     *
     * @return bool[]
     */
    private function getOpenAPINullablesSetToNull(): array
    {
        return $this->openAPINullablesSetToNull;
    }

    /**
     * Setter - Array of nullable field names deliberately set to null.
     *
     * @param bool[] $openAPINullablesSetToNull
     */
    private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
    {
        $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
    }

    /**
     * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
     * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
     * $this->openAPINullablesSetToNull array.
     *
     * @param mixed $defaultValue
     */
    private function setIfExists(string $variableName, array $fields, $defaultValue): void
    {
        if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
            $this->openAPINullablesSetToNull[] = $variableName;
        }

        $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
    }
}
